package com.mcr.reggie.controller;

import com.mcr.reggie.common.R;
import com.mcr.reggie.entity.ShoppingCart;
import com.mcr.reggie.service.ShoppingCartService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/shoppingCart")
public class ShoppingCartController {
    /**
     *
     *
     *   *   *  *   *   **   *   *前台*   *   **   *   **   *   **   *   *
     *
     *
     */
    @Autowired
    ShoppingCartService shoppingCartService;
    @ApiOperation(value = "添加购物车")
    @PostMapping("/add")
    public R<ShoppingCart> add(@RequestBody ShoppingCart sc){
        ShoppingCart shoppingCart = shoppingCartService.addShoppingCart(sc);
        return R.success(shoppingCart);
    }
    @ApiOperation(value = "购物车中剔除商品")
    @PostMapping("/sub")
    public R<String> sub(@RequestBody ShoppingCart sc){
        shoppingCartService.subShoppingCart(sc);
        return R.success("减少成功！！");
    }
    @ApiOperation(value = "查看自己的购物车数据")
    @GetMapping("/list")
    public R<List<ShoppingCart>> list(){
        List<ShoppingCart> shoppingCartList=shoppingCartService.getList();
        return R.success(shoppingCartList);
    }
    @ApiOperation(value = "清空购物车")
    @DeleteMapping("/clean")
    public R<String> delete(){
        shoppingCartService.cleanShoppingCart();
        return R.success("清空成功");
    }
}
